import { _decorator, Animation, Component, Node, PlaneCollider, RigidBody2D } from 'cc';
import { IState } from '../../fsm/State';
import { Enemy } from './Enemy';
import { StateDefine } from '../Config';
const { ccclass, property } = _decorator;

@ccclass('EnemyState')
export abstract class EnemyState implements IState<StateDefine> {
    enemyBase: Enemy;
    animation: Animation;
    id: StateDefine;
    anim: string;
    rb: RigidBody2D | null = null;

    triggerCalled: boolean = false;
    stateTime: number = 0;
    // collider: Collider2D | null = null;
    constructor(name: StateDefine, _enemy: Enemy, anim: StateDefine) {
        this.enemyBase = _enemy;
        this.animation = _enemy.animation;
        this.id = name;
        this.anim = anim;
        this.rb = this.enemyBase.rigidBody;
    }

    onEnter() {
        // console.info("onEnter => " + this.anim);
        this.triggerCalled = false;
        this.animation.play(this.anim);

    }
    onExit() {
        // this.enemy.BusyFor(10);
        // console.info("now onExit => "+this.id);
    }
    update(deltaTime: number) {
        this.stateTime -= deltaTime;
        // console.info(this.anim);
        // console.info(this.stateTime);
    }
    onDestory() { }

    canTransit(to: StateDefine): boolean {
        return true;
    }
    AnimationFinishTrigger(): void {
        this.triggerCalled = true;
    }
}


